﻿using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using habbo.Database.Maps;
using NHibernate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace habbo.Database
{
    class NHibernateManager
    {
        private readonly ISessionFactory _dbSessionFactroy;

        public NHibernateManager(string ConnectionString)
        {
            _dbSessionFactroy = createFactory(ConnectionString);
        }

        private ISessionFactory createFactory(string ConnectionString)
        {
            return Fluently.Configure()
                .Database(MySQLConfiguration.Standard.ConnectionString(ConnectionString))
                .Cache(c => c.UseQueryCache().UseSecondLevelCache().UseMinimalPuts())
                .Mappings(m => m.FluentMappings.Add<characterMap>())
                .Mappings(m => m.FluentMappings.Add<character_friendMap>())
                .Mappings(m => m.FluentMappings.Add<server_settingMap>())
                .Mappings(m => m.FluentMappings.Add<private_roomMap>())
                .BuildSessionFactory();
        }

        public ISessionFactory getFactory()
        {
            return _dbSessionFactroy;
        }
    }
}
